package org.outlook.commons.ui.components.table;

import java.awt.Component;

import javax.swing.JComponent;
import javax.swing.JTable;

public class ToolTipFractionCellRenderer extends FractionCellRenderer {

	private static final long serialVersionUID = 1L;

	public ToolTipFractionCellRenderer(int integer, int fraction,
			int maxFraction, int align) {
		super(integer, fraction, align);
		this.maxFraction = maxFraction; // Number of tooltip fraction digits
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		Component comp = super.getTableCellRendererComponent(table, value,
				isSelected, hasFocus, row, column);

		if (value != null && value instanceof Number) {
			formatter.setMaximumIntegerDigits(integer);
			formatter.setMaximumFractionDigits(maxFraction);
			formatter.setMinimumFractionDigits(maxFraction);
			((JComponent) comp).setToolTipText(formatter
					.format(((Number) value).doubleValue()));
		}

		return comp;
	}

	protected int maxFraction;
}